#!/bin/sh

DATA_HOME=${XDG_DATA_HOME:-"$HOME/.local/share"}
index="$DATA_HOME/music/index"

i() {
	probe=$(ffprobe "$1" 2>&1)
	album=$(echo "$probe" | grep -i 'album ' | cut -d ':' -f2 | cut -d ' ' -f2-)
	album_artist=$(echo "$probe" | grep -i 'album_artist ' | cut -d ':' -f2 | cut -d ' ' -f2-)
	title=$(echo "$probe" | grep -i 'title ' | head -n1 | cut -d ':' -f2 | cut -d ' ' -f2-)
	echo "$album_artist/$album/$titlefile://$1"
}

if [ "$1" != '-a' ]
then
	echo >"$index"
fi

find "$(pwd)" -type f | while read -r song; do i "$song"; done >>"$index"
